home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1997 May / EnigmA AMIGA RUN 18 (1997)(G.R. Edizioni)(IT)[!][issue 1997-05][EAR-CD II].iso / earcd / misc / emu / arosdev.lha / AROS / scripts / genprotos.h < prev    next >
Text File  |  1997-02-04  |  3KB  |  159 lines

  1. #NAME */
  2. #     #include <clib/exec_protos.h>
  3. #
  4. #     __AROS_LH3(void, InitStruct,
  5. #
  6. #/*  SYNOPSIS */
  7. #     __AROS_LHA(APTR,  initTable, A1),
  8. #     __AROS_LHA(APTR,  memory,    A2),
  9. #     __AROS_LHA(ULONG, size,      D0),
  10. #
  11. #/*  LOCATION */
  12. #     struct ExecBase *, SysBase, 13, Exec)
  13. #
  14. #
  15. #LP3(void, InitStruct,
  16. #    APTR, initTable, A1,
  17. #    APTR, memory, A2,
  18. #    ULONG, size, D0,
  19. #    struct ExecBase *, SysBase, -13, Exec)
  20. #
  21. ##define InitStruct(initTable, memory, size) \
  22. #__AROS_LC3(void, InitStruct, \
  23. # __AROS_LA(APTR,  initTable, A1), \
  24. # __AROS_LA(APTR,  memory,    A2), \
  25. # __AROS_LA(ULONG, size,      D0), \
  26. #        struct ExecBase *, SysBase, 13, Exec)
  27. #
  28.  
  29. BEGIN {
  30.     indir="compiler/include"
  31.     outdir=indir;
  32.  
  33.     basename_lp=indir "/clib/" tolower(lib) "_protos.h"
  34.     basename_lc=indir "/defines/" tolower(lib) ".h"
  35.     infile_lp=basename_lp
  36.     infile_lc=basename_lc
  37.     out_lp=basename_lp ".new"
  38.     out_lc=basename_lc ".new"
  39.  
  40.     todo=2;
  41.  
  42.     printf ("") > out_lp;
  43.     printf ("") > out_lc;
  44.  
  45.     while ((getline < infile_lp) > 0 && todo)
  46.     {
  47.     if ($1 == "Prototypes")
  48.         todo --;
  49.     else if ($1 == "#ifndef" && define_lp=="")
  50.     {
  51.         define_lp = $2;
  52.     }
  53.     else if (todo < 2)
  54.         todo --;
  55.  
  56.     print >> out_lp;
  57.     }
  58.  
  59.     todo=2;
  60.  
  61.     while ((getline < infile_lc) > 0 && todo)
  62.     {
  63.     if ($1 == "Defines")
  64.         todo --;
  65.     else if ($1 == "#ifndef" && define_lc=="")
  66.     {
  67.         define_lc = $2;
  68.     }
  69.     else if (todo < 2)
  70.         todo --;
  71.  
  72.     print >> out_lc;
  73.     }
  74. }
  75. /^#?[ \t]*NAME[ \t]*(\*\/)?[ \t]*$/ {
  76.     state=0;
  77.     args=0;
  78.  
  79.     while (getline > 0)
  80.     {
  81.     if (state==0)
  82.     {
  83.         if (match ($0,"^#?[ \t]*AROS_LH"))
  84.         {
  85.         line=$0;
  86.         sub(/#?[ \t]*$/,"",line);
  87.         match(line,/[a-zA-Z0-9_]+,$/);
  88.         name=substr(line,RSTART,RLENGTH-1);
  89.  
  90.         sub(/^#?[ \t]*/,"",line);
  91.         f=line;
  92.         state=1;
  93.         }
  94.     }
  95.     else if (state == 1)
  96.     {
  97.         if (match ($0,"^#?[ \t]*AROS_LH"))
  98.         {
  99.         line=$0;
  100.         sub(/[ \t]*$/,"",line);
  101.         sub(/^#?[ \t]*/,"",line);
  102.         f=f "@1" line;
  103.  
  104.         match(line,/,[ \t]*[a-zA-Z0-9_]+[ \t]*,/);
  105.         arg=substr(line,RSTART+1,RLENGTH-2);
  106.         sub(/[ \t]*$/,"",arg);
  107.         sub(/^[ \t]*/,"",arg);
  108.         a[args++] = arg;
  109. #print name ":" arg
  110.         }
  111.         else if (match ($0, /^#?(\/\*)?[ \t]*LOCATION[ \t]*(\*\/)?[ \t]*$/))
  112.         {
  113.         state=2;
  114.         }
  115.     }
  116.     else if (state == 2)
  117.     {
  118.         if ($1 != "")
  119.         {
  120.         line=$0;
  121.         sub(/[ \t]*$/,"",line);
  122.         sub(/^#?[ \t]*/,"",line);
  123.         f=f "@1" line;
  124.         break;
  125.         }
  126.     }
  127.     }
  128.  
  129.     line=f;
  130.     gsub("@1","\n    ",line);
  131.     gsub("AROS_LH","AROS_LP",line);
  132.     print line >> out_lp;
  133.     print "" >> out_lp;
  134.  
  135.     printf ("#define %s(", name) >> out_lc;
  136.     for (t=0; t<args; t++)
  137.     {
  138.     printf ("%s", a[t]) >> out_lc;
  139.  
  140.     if (t+1<args)
  141.         printf (", ") >> out_lc;
  142.     }
  143.     printf (") \\\n") >> out_lc
  144.     line=f;
  145.     gsub("@1"," \\\n    ",line);
  146.     gsub("AROS_LH","AROS_LC",line);
  147.     print "    " line >> out_lc;
  148.     print "" >> out_lc;
  149. }
  150. END {
  151.     print "\n#endif /* " define_lc " */" >> out_lc
  152.     print "\n#endif /* " define_lp " */" >> out_lp
  153.  
  154.     close (infile_lc);
  155.     close (out_lc);
  156.     close (infile_lp);
  157.     close (out_lp);
  158. }
  159.